<?php

namespace App\Http\Controllers\V1_bak;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class PhotoController extends Controller
{
    public function syncPhoto()
    {
//        DB::table('photo')
//            ->where('Pid','>=','2646')
//            ->delete();
//        die();
        $field = "PicPath_0,PicPath_1,PicPath_2,PicPath_3,PicPath_4,PicPath_5,PicPath_6,PicPath_7,PicPath_8,PicPath_9,PicPath_10
        PicPath_11,PicPath_12,PicPath_13,PicPath_14,Name_en,ProId,CateId";
        $prodcut = DB::table('products')
            ->selectRaw($field)
            ->get()
        ;
        $prodcut =toArr($prodcut);
        $items = [];
        foreach ($prodcut as $key=>$val){
            for ($i=0;$i<15;$i++){
                $secItem = [];
                if(!empty($val['PicPath_'.$i])){
                    $secItem['Name']=$val['Name_en'];
                    $secItem['PicPath']=$val['PicPath_'.$i];
                    $secItem['IsSystem']='products';
                    $secItem['CateId']=0;
                    $secItem['ProId']=$val['ProId'];
                    $items[]=$secItem;
                }
            }
        }
        DB::table('photo')->insert($items);

    }
}
